import { _decorator, Component, MeshRenderer, Node, tween, v3, Vec3 } from "cc";
const { ccclass, property } = _decorator;

@ccclass("ShaderCaseScaleNode")
export class ShaderCaseScaleNode extends Component {
    @property({ displayName: "延迟" })
    delay: number = 0;
    @property({ displayName: "周期" })
    cycle: number = 1;
    @property({ displayName: "最大缩放" })
    maxScale: number = 10;

    private _minScale = v3();
    private _maxScale = v3(15, 15, 15);
    private _time = 1;
    start() {
        this._time = this.cycle;
        this._maxScale.set(this.maxScale, this.maxScale, this.maxScale);
        this.node.setScale(Vec3.ZERO);
        this.scheduleOnce(() => {
            tween(this.node)
                .to(this._time, { scale: this._maxScale })
                .to(0, { scale: this._minScale })
                .union()
                .repeatForever()
                .start();
        }, this.delay);
    }

    protected update(dt: number): void {
        const material = this.node.getComponent(MeshRenderer).getMaterialInstance(0);

        material.setProperty("scale", this.node.scale.x * 3);
    }
}
